﻿//-------------------------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , JamSoft TECH, Ltd .
//-------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

// 本系统生成的类库
using DotNet.Business;
using DotNet.Utilities;

/// <remarks>
/// UserAdmin
/// 用户管理
/// 
/// 修改纪录
///	版本：1.0 2011.09.05 LiangMingMing  创建代码。 
/// <author>
///     <verison>1.0</verison>
///		<name>LiangMingMing</name>
///		<date>2011.09.05</date>
///		<description>用户管理</description>
/// </author> 
/// </remarks>
public partial class UserAdmin : BasePage
{

    // **********************************************************************************************
    // *                                                                                            * 
    // *                             Public Variate    公共变量                                     *
    // *                                                                                            * 
    // **********************************************************************************************

    /// <summary>
    /// 用户数据表
    /// </summary>
    private DataTable DTUser
    {
        get
        {
            return Utilities.GetFromSession("_DTUser") as DataTable;
        }
        set
        {
            Utilities.AddSession("_DTUser", value);
        }
    }
    /// <summary>
    /// 访问权限
    /// </summary>
    private bool PermissionAccess = true;
    /// <summary>
    /// 编辑权限
    /// </summary>
    private bool PermissionEdit = true;
    /// <summary>
    /// 注册权限
    /// </summary>
    private bool PermissionRegistration = true;
    /// <summary>
    /// 设置密码权限
    /// </summary>
    private bool PermissionSetPassword = true;
    /// <summary>
    /// 解锁权限
    /// </summary>
    private bool PermissionPass = true;
    /// <summary>
    /// 锁定权限
    /// </summary>
    private bool PermissionLock = true;
    /// <summary>
    /// 删除权限
    /// </summary>
    private bool PermissionDelete = true;
    /// <summary>
    /// 查询权限
    /// </summary>
    private bool PermissionSearch = true;
    /// <summary>
    /// 多语言变量（添加到收藏夹）
    /// </summary>
    public string ToolbarFavorite = string.Empty;
    /// <summary>
    /// 多语言变量（显示隐藏左边菜单）
    /// </summary>
    public string ToolbarShowhideLeftFrame = string.Empty;
    /// <summary>
    /// 多语言变量（显示隐藏TOP页面）
    /// </summary>
    public string ToolbarShowhideTopFrame = string.Empty;
    /// <summary>
    /// 多语言变量（帮助中心）
    /// </summary>
    public string ToolbarHelp = string.Empty;
    /// <summary>
    /// 多语言-按钮（全选/全不选）
    /// </summary>
    public string ButtonCheckAll = string.Empty;
    /// <summary>
    /// 多语言-按钮（注册）
    /// </summary>
    public string ButtonRegistration = string.Empty;
    /// <summary>
    /// 多语言-按钮（设置密码）
    /// </summary>
    public string ButtonSetPassword = string.Empty;
    /// <summary>
    /// 多语言-按钮（解锁）
    /// </summary>
    public string ButtonPass = string.Empty;
    /// <summary>
    /// 多语言-按钮（锁定）
    /// </summary>
    public string ButtonLock = string.Empty;
    /// <summary>
    /// 多语言-按钮（删除）
    /// </summary>
    public string ButtonDelete = string.Empty;
    /// <summary>
    /// 多语言-GridView( 全选复选框 ）
    /// </summary>
    public string CheckedCheckAll = string.Empty;
    /// <summary>
    /// 多语言-GridViewToolTip( 编辑提示信息 ）
    /// </summary>
    public string ToopTipEdit = string.Empty;
    /// <summary>
    /// 多语言-GridViewToolTip( 删除提示信息 ）
    /// </summary>
    public string ToopTipDelete = string.Empty;
    /// <summary>
    /// 多语言-GridViewToolTip(未找到查询内容。）
    /// </summary>
    public string ToopTipSearch = string.Empty;
    /// <summary>
    /// 多语言-提示信息（你确认为所选项设置密码吗？）
    /// </summary>
    public string MSGSetPassword = string.Empty;
    /// <summary>
    /// 多语言-提示信息（你确认解锁所选项吗？）
    /// </summary>
    public string MSGPass = string.Empty;
    /// <summary>
    /// 多语言-提示信息（你确认锁定所选项吗？）
    /// </summary>
    public string MSGLock = string.Empty;
    /// <summary>
    /// 多语言-提示信息( 你确认删除所选项吗？）
    /// </summary>
    public string MSGDelete = string.Empty;

    // **********************************************************************************************
    // *                                                                                            * 
    // *                             InitializeComponent  初始化                                    * 
    // *                                                                                            * 
    // **********************************************************************************************

    #region private void PageOnLoad() 页面初次加载时的动作
    /// <summary>
    /// 页面初次加载时的动作
    /// </summary>
    private void PageOnLoad()
    {
        // 读取参数
        try
        {
            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 从数据库表获取参数
            this.GetDataBaseParamter();
            // 获取下拉列表
            this.GetItemDetails();
            // 获取参数
            this.GetParamter();
            // 获取用户列表
            this.DoSearch();
            // 定位焦点到查询文本框
            this.txtSearch.Focus();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
    }
    #endregion

    // **********************************************************************************************
    // *                                                                                            * 
    // *                                       Method   操作方法                                    * 
    // *                                                                                            * 
    // **********************************************************************************************

    #region private void Localization() 多语言国际化加载
    /// <summary>
    /// 多语言国际化加载
    /// </summary>
    private void Localization()
    {
        // 多语言国际化加载
        ResourceManagerWrapper.Instance.LoadResources(Server.MapPath("../../../../Resource/Localization/"));
        // 获取语言信息
        this.GetLanguageResource(Utilities.GetCurrentLanguage(this.UserInfo));
    }
    #endregion

    #region private void GetLanguageResource(string languages) 获取语言
    /// <summary>
    /// 获取语言
    /// </summary>
    /// <param name="languages">语言类型</param>
    private void GetLanguageResource(string languages)
    {
        /// <以变量形式加载，刷新时会被刷掉所以得一直加载着>
        // 添加到收藏夹
        this.ToolbarFavorite = ResourceManagerWrapper.Instance.Get(languages, "Toolbar.Favorite");
        // 显示隐藏左边菜单
        this.ToolbarShowhideLeftFrame = ResourceManagerWrapper.Instance.Get(languages, "Toolbar.ShowhideLeftFrame");
        // 显示隐藏TOP页面
        this.ToolbarShowhideTopFrame = ResourceManagerWrapper.Instance.Get(languages, "Toolbar.ShowhideTopFrame");
        // 帮助中心
        this.ToolbarHelp = ResourceManagerWrapper.Instance.Get(languages, "Toolbar.Help");
        // 按钮-全选/反选
        this.ButtonCheckAll = ResourceManagerWrapper.Instance.Get(languages, "Button.CheckAll");
        // 按钮-删除
        this.ButtonDelete = ResourceManagerWrapper.Instance.Get(languages, "Button.Delete");
        // 按钮-锁定
        this.ButtonLock = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_btnLock");
        // 按钮-解锁
        this.ButtonPass = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_btnPass");
        // 按钮-注册
        this.ButtonRegistration = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_btnRegistration");
        // 按钮-设置密码
        this.ButtonSetPassword = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_btnSetPassword");
        // GridView 全选复选框
        this.CheckedCheckAll = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsChecked");
        // GridView 编辑提示信息
        this.ToopTipEdit = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsToopTipEdit");
        // GridView 删除提示信息
        this.ToopTipDelete = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsToopTipDelete");
        // GridView 未找到查询内容。
        this.ToopTipSearch = ResourceManagerWrapper.Instance.Get(languages, "MSG50025");
        // 下拉框请选择
        this.txtPleseSelect.Value = ResourceManagerWrapper.Instance.Get(languages, "DropDownList.Select");
        //--- 提示信息 ----
        // 你确认为所选项设置密码吗？
        this.MSGSetPassword = ResourceManagerWrapper.Instance.Get(languages, "MSG50019");
        // 你确认解锁所选项吗？
        this.MSGPass = ResourceManagerWrapper.Instance.Get(languages, "MSG50020");
        // 你确认锁定所选项吗？
        this.MSGLock = ResourceManagerWrapper.Instance.Get(languages, "MSG50021");
        // 你确认删除所选项吗？
        this.MSGDelete = ResourceManagerWrapper.Instance.Get(languages, "MSG50022");
        /// <用的是控件，所以不怕被刷新>
        if (!Page.IsPostBack)
        {
            // 标题
            this.Title = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx");
            // 用户管理
            this.ltlTittle.Text = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ltlTittle");
            // 只显示有效的
            this.ckbEnabled.Text = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ckbEnabled");
            // 角色：
            this.ltlRole.Text = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ltlRole");
            // Groupbox查询文字：
            this.ltlSearch.Text = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ltlSearch");
            // 查询文字：
            this.ltlSearchContent.Text = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ltlSearchContent");
            // 查询：
            this.btnSearch.Text = ResourceManagerWrapper.Instance.Get(languages, "Button.Search");
            //---分页---
            // 跳转到第
            this.aspNetPager.TextBeforePageIndexBox = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.TextBeforePageIndexBox");
            // 页
            this.aspNetPager.TextAfterPageIndexBox = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.TextAfterPageIndexBox");
            // 首页
            this.aspNetPager.FirstPageText = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.FirstPageText");
            // 尾页
            this.aspNetPager.LastPageText = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.LastPageText");
            // 上页
            this.aspNetPager.PrevPageText = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.PrevPageText");
            // 下页
            this.aspNetPager.NextPageText = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.NextPageText");
            // 转到
            this.aspNetPager.SubmitButtonText = ResourceManagerWrapper.Instance.Get(languages, "AspNetPager.SubmitButtonText");
            // 序号
            this.gridView.Columns[0].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsNumber");
            // 全选
            //this.gridView.Columns[1].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.");
            //---列表---
            // 来源
            this.gridView.Columns[2].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsUserFrom");
            // 用户名
            this.gridView.Columns[3].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsUserName");
            // 姓名
            this.gridView.Columns[4].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsRealname");
            // 默认角色
            this.gridView.Columns[5].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsRoleName");
            // 有效
            this.gridView.Columns[6].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsEnabled");
            // 备注
            this.gridView.Columns[7].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsDescription");
            // 编辑
            this.gridView.Columns[8].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsEdit");
            // 删除
            this.gridView.Columns[9].HeaderText = ResourceManagerWrapper.Instance.Get(languages, "UserAdmin.aspx_ColumnsDelete");
            //---提示信息---
            // 提示信息：删除失败。
            this.hdfDeleteLose.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50004");
            // 提示信息：删除成功。
            this.hdfDeleteSuccess.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50003");
            // 提示信息：锁定失败。
            this.hdfLockLose.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50015");
            // 提示信息：锁定成功。
            this.hdfLockSuccess.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50016");
            // 提示信息：解锁失败。
            this.hdfPassLose.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50017");
            // 提示信息：解锁成功。
            this.hdfPassSuccess.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50018");
            // 提示信息：未找到查询内容。
            this.hdfSearch.Value = ResourceManagerWrapper.Instance.Get(languages, "MSG50005");
        }
    }
    #endregion

    #region private void GetPermission() 获取权限
    /// <summary>
    /// 获取权限
    /// </summary>
    private void GetPermission()
    {
        // 获取访问权限
        this.PermissionAccess = this.IsAuthorized("UserAdmin.Access");
        // 获取删除权限
        this.PermissionDelete = this.IsAuthorized("UserAdmin.Delete");
        // 获取编辑权限
        this.PermissionEdit = this.IsAuthorized("UserAdmin.Edit");
        // 获锁定权限
        this.PermissionLock = this.IsAuthorized("UserAdmin.Lock");
        // 获取解锁权限
        this.PermissionPass = this.IsAuthorized("UserAdmin.Pass");
        // 获取注册权限
        this.PermissionRegistration = this.IsAuthorized("UserAdmin.Registration");
        // 获取查询权限
        this.PermissionSearch = this.IsAuthorized("UserAdmin.Search");
        // 获取密码权限
        this.PermissionSetPassword = this.IsAuthorized("UserAdmin.SetPassword");
        // 若没有访问权限，就应该跳转到没权限的页面了
        if (this.PermissionAccess)
        {
            Page.Response.Redirect(Utilities.AccessDenyPage);
        }
    }
    #endregion

    #region private void GetParamter() 读取参数
    /// <summary>
    /// 读取参数
    /// </summary>
    private void GetParamter()
    {
        // 获取查询参数
        if (Page.Request["Search"] != null)
        {
            this.txtSearch.Text = Page.Request["Search"].ToString();
        }
        // 获取角色参数
        if (Page.Request["Role"] != null)
        {
            this.cmbRole.SelectedValue = Page.Request["Role"].ToString();
            this.cmbRole.Enabled = false;
        }
    }
    #endregion

    #region private void GetDataBaseParamter() 从数据库读取参数
    /// <summary>
    /// 从数据库读取参数
    /// </summary>
    private void GetDataBaseParamter()
    {
        // 实例化参数业务操作类
        BaseParameterManager parameterManager = new BaseParameterManager(this.UserCenterDbHelper, this.UserInfo);
        // 获取参数
        string enabled = parameterManager.GetParameter("User", this.UserInfo.Id, "UserAdmin.Enabled");
        // 给是否有效赋值
        if (enabled.Length > 0 && enabled.Equals("0"))
        {
            this.ckbEnabled.Checked = false;
        }
        //string pageSize = parameterManager.GetParameter("User", this.UserInfo.Id, "UserAdmin.PageSize");
        //if (pageSize.Length > 0)
        //{
        //    this.myNavigator.PageSize = int.Parse(pageSize);
        //}
    }
    #endregion

    #region private void SaveDataBaseParamter() 保存参数
    /// <summary>
    /// 保存参数
    /// </summary>
    private void SaveDataBaseParamter()
    {
        // 实例化参数业务操作类
        BaseParameterManager parameterManager = new BaseParameterManager(this.UserCenterDbHelper, this.UserInfo);
        // 设置参数
        parameterManager.SetParameter("User", this.UserInfo.Id, "UserAdmin.Enabled", this.ckbEnabled.Checked ? "1" : "0");
        // 以换用AspNetPager分页控件
        //parameterManager.SetParameter("User", this.UserInfo.Id, "UserAdmin.PageSize", this.myNavigator.PageSize.ToString());
    }
    #endregion

    #region private void GetItemDetails() 绑定下拉筐数据
    /// <summary>
    /// 绑定下拉筐数据
    /// </summary>
    private void GetItemDetails()
    {
        DotNetService dotNetService = new DotNetService();
        // 获取角色绑定数据
        DataTable dataTable = dotNetService.RoleService.GetDataTable(this.UserInfo);
        // 绑定数据源
        this.cmbRole.DataSource = dataTable;
        // 绑定显示字段
        this.cmbRole.DataTextField = BaseRoleEntity.FieldRealName;
        // 绑定主键字段
        this.cmbRole.DataValueField = BaseRoleEntity.FieldId;
        // 绑定
        this.cmbRole.DataBind();
        // 插入一列空列
        this.cmbRole.Items.Insert(0, new ListItem(this.txtPleseSelect.Value, string.Empty));
    }
    #endregion

    #region private void SetButtomState() 设置按钮状态
    /// <summary>
    /// 设置按钮状态
    /// </summary>
    private void SetButtomState()
    {
        // 判断GridView列表是否有数据
        if (this.gridView.Rows.Count == 0)
        {
            // 全部屏蔽按钮状态
            this.btnCheckAll.Visible = false;
            this.btnDelete.Visible = false;
            this.btnPass.Visible = false;
            this.btnLock.Visible = false;
            this.btnSetPassword.Visible = false;
        }
        else
        {
            // 设置按钮状态为可见并按权限分配
            this.btnCheckAll.Visible = true;
            this.btnSetPassword.Visible = this.PermissionSetPassword;
            this.btnPass.Visible = this.PermissionPass;
            this.btnLock.Visible = this.PermissionLock;
            this.btnDelete.Visible = this.PermissionDelete;
            //this.btnSearch.Visible = this.PermissionSearch;            
        }
        // 设置编辑权限
        this.gridView.Columns[this.gridView.Columns.Count - 2].Visible = this.PermissionEdit;
        // 设置删除权限
        this.gridView.Columns[this.gridView.Columns.Count - 1].Visible = this.PermissionDelete;
    }
    #endregion

    #region private void Search() 查询
    /// <summary>
    /// 查询
    /// </summary>
    private void Search()
    {
        // 设置当前页索引
        this.gridView.PageIndex = 0;
        try
        {
            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 保存参数
            this.SaveDataBaseParamter();
            // 查询
            this.DoSearch();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
        // 是否显示提示信息
        if ((Utilities.ShowInformation) && (this.gridView.Rows.Count == 0))
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "searchFailure", "<script>alert('" + this.hdfSearch.Value + "');</script>");
        }
    }
    #endregion

    #region private void DoSearch() 查询
    /// <summary>
    /// 进行查询
    /// </summary>
    private void DoSearch()
    {
        // 获取查询文本字符串
        string search = this.txtSearch.Text;
        // 实例化用户业务操作类
        BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, this.UserInfo);
        // 定义审批状态
        string auditStates = string.Empty;
        // 定义角色组
        string[] roleIDs = null;
        // 判断角色选择框选择是否为空
        if (!string.IsNullOrEmpty(this.cmbRole.SelectedValue))
        {
            // 获取角色选择的主键
            roleIDs = new string[] { this.cmbRole.SelectedValue };
        }
        // 查询返回数据表
        DataTable dataTable = userManager.Search(search, roleIDs, null, auditStates);
        // 把已删除的过滤掉（假删除）
        BaseBusinessLogic.SetFilter(dataTable, BaseUserEntity.FieldDeletionStateCode, "0");
        // 过滤有效无效
        if (this.ckbEnabled.Checked)
        {
            BaseBusinessLogic.SetFilter(dataTable, BaseUserEntity.FieldEnabled, "1");
        }
        // 设置排序
        dataTable.DefaultView.Sort = this.SortExpression + " " + this.SortDire;
        // 将数据表赋值给公共变量用户表
        this.DTUser = dataTable;
        // 通过AspNetPager分页控件绑定数据
        this.BindAspNetPagerData(this.gridView, aspNetPager, this.DTUser);
        // 设置按钮状态
        this.SetButtomState();
        // 设置焦点
        this.txtSearch.Focus();
    }
    #endregion

    #region private void DeleteMark(string id) 删除事件
    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="id">代码</param>
    private void DeleteMark(string id)
    {
        // 返回值
        int returnValue = 0;
        try
        {
            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 实例化用户业务逻辑操作层
            BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, this.UserInfo);
            // 执行删除事件并返回结果
            returnValue = userManager.SetDeleted(id);
            // 重新获取数据
            this.DoSearch();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
        // 是否显示提示信息
        if (Utilities.ShowInformation)
        {
            // 返回值是否大于零
            if (returnValue > 0)
            {
                // 显示操作成功提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "DeleteSucceed", "<script>alert('" + this.hdfDeleteSuccess.Value + "');</script>");
            }
            else
            {
                // 显示操作失败提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "DeleteFailure", "<script>alert('" + this.hdfDeleteLose.Value + "');</script>");
            }
        }
    }
    #endregion

    #region private int BathDelete() 批量删除
    /// <summary>
    /// 批量删除
    /// </summary>
    /// <returns>影响的行数</returns>
    private int BathDelete()
    {
        // 返回值
        int returnValue = 0;
        // 获取勾选的代码组
        string[] ids = Utilities.GetSelecteIds(this.gridView);
        try
        {

            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 实例化用户业务逻辑操作层
            BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, this.UserInfo);
            // 执行删除事件并返回结果
            returnValue = userManager.SetDeleted(ids);
            // 重新获取数据
            this.DoSearch();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
        // 是否显示提示信息
        if (Utilities.ShowInformation)
        {
            // 返回值是否大于零
            if (returnValue > 0)
            {
                // 显示操作成功提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "DeleteSucceed", "<script>alert('" + this.hdfDeleteSuccess.Value + "');</script>");
            }
            else
            {
                // 显示操作失败提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "DeleteFailure", "<script>alert('" + this.hdfDeleteLose.Value + "');</script>");
            }
        }
        // 返回结果
        return returnValue;
    }
    #endregion

    #region private int Pass() 批量解锁
    /// <summary>
    /// 批量解锁
    /// </summary>
    /// <returns>影响的行数</returns>
    private int BathPass()
    {
        // 返回值
        int returnValue = 0;
        // 获取勾选的代码组
        string[] ids = Utilities.GetSelecteIds(this.gridView);
        try
        {
            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 实例化用户业务逻辑操作层
            BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, this.UserInfo);
            // 锁定用户
            returnValue = userManager.SetProperty(BaseBusinessLogic.FieldId, ids, new KeyValuePair<string, object>(BaseUserEntity.FieldEnabled, 1));
            // 重新获取数据
            this.DoSearch();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
        // 是否显示提示信息
        if (Utilities.ShowInformation)
        {
            if (returnValue > 0)
            {
                // 显示操作成功提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "bathPassSucceed", "<script>alert('" + this.hdfPassSuccess.Value + "');</script>");
            }
            else
            {
                // 显示操作失败提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "bathPassFailure", "<script>alert('" + this.hdfPassLose.Value + "');</script>");
            }
        }
        return returnValue;
    }
    #endregion

    #region private int BathLock() 批量锁定
    /// <summary>
    /// 批量锁定
    /// </summary>
    /// <returns>影响的行数</returns>
    private int BathLock()
    {
        // 返回值
        int returnValue = 0;
        // 获取勾选的代码组
        string[] ids = Utilities.GetSelecteIds(this.gridView);
        try
        {
            // 打开数据库连接
            this.UserCenterDbHelper.Open();
            // 实例化用户业务逻辑操作层
            BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, this.UserInfo);
            // 解锁用户
            returnValue = userManager.SetProperty(BaseBusinessLogic.FieldId, ids, new KeyValuePair<string, object>(BaseUserEntity.FieldEnabled, 0));
            // 重新获取数据
            this.DoSearch();
        }
        catch (Exception ex)
        {
            // 记录日志
            this.LogException(ex);
            // 抛出错误
            throw ex;
        }
        finally
        {
            // 关闭数据库连接
            this.UserCenterDbHelper.Close();
        }
        // 是否显示提示信息
        if (Utilities.ShowInformation)
        {
            if (returnValue > 0)
            {
                // 显示操作成功提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "bathLockSucceed", "<script>alert('" + this.hdfLockSuccess.Value + "');</script>");
            }
            else
            {
                // 显示操作失败提示信息
                this.ClientScript.RegisterStartupScript(this.GetType(), "bathLockFailure", "<script>alert('" + this.hdfLockLose.Value + "');</script>");
            }
        }
        return returnValue;
    }
    #endregion

    // **********************************************************************************************
    // *                                                                                            * 
    // *                                       EventArgs    事件方法                                * 
    // *                                                                                            * 
    // ********************************************************************************************** 

    #region protected void Page_Load(object sender, EventArgs e) 页面初次加载的动作
    /// <summary>
    /// 页面初次加载的动作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        // 加载多语言
        this.Localization();
        // 获取权限
        //this.GetPermission();
        // 判断是否回发
        if (!Page.IsPostBack)
        {
            // 页面初次加载时的动作
            this.PageOnLoad();
        }
    }
    #endregion

    #region protected void cmbRole_SelectedIndexChanged(object sender, EventArgs e) 角色选择时事件
    /// <summary>
    /// 角色选择时事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void cmbRole_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Search();
    }
    #endregion

    #region protected void btnSearch_Click(object sender, EventArgs e) 查询
    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        // 进行查询
        this.Search();
    }
    #endregion

    #region protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) 数据列表绑定时发生
    /// <summary>
    /// 数据列表绑定时发生
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // 绑定行数据
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // 设置鼠标选择行颜色
            //e.Row.Attributes.Add("onmouseover", "color =this.style.backgroundColor;this.style.backgroundColor='LemonChiffon';document.getElementById('gridView_ctl" + ((e.Row.RowIndex + 2) < 10 ? "0" + (e.Row.RowIndex + 2).ToString() : (e.Row.RowIndex + 2).ToString()).ToString() + "_lblPageIndex" + "').innerHTML=\"<img id='trigon' src = '../../../../images/Default/gridview/San.gif' style='float:left; margin-top:5px; margin-left:2px;'/>\"");
            //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = color;document.getElementById('gridView_ctl" + ((e.Row.RowIndex + 2) < 10 ? "0" + (e.Row.RowIndex + 2).ToString() : (e.Row.RowIndex + 2).ToString()).ToString()+ "_lblPageIndex" + "').innerHTML=''");
            e.Row.Attributes.Add("onmouseover", "color =this.style.backgroundColor;this.style.backgroundColor='LemonChiffon';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = color;");
            // 是否有删除权限
            if (this.PermissionDelete)
            {
                // 获取删除单元
                TableCell tableCell = e.Row.Cells[this.gridView.Columns.Count - 1];
                // 获取删除按钮
                LinkButton btnLinkDelete = (LinkButton)tableCell.Controls[0];
                // 判断是否为空
                if (btnLinkDelete != null)
                {
                    // 执行绑定删除事件
                    string strScript = "return confirm('您确认要删除吗？');";
                    btnLinkDelete.Attributes.Add("onclick", strScript);
                }
            }
        }
        // 判断是是否是标题行
        if (e.Row.RowType == DataControlRowType.Header)
        {
            // 循环列
            foreach (DataControlField dataControlField in this.gridView.Columns)
            {
                // 判断当前排序字段
                if (dataControlField.SortExpression.Equals(this.SortExpression))
                {
                    // 创建label
                    Label label = new Label();
                    // 加上双向排序标符
                    label.Text = this.SortDire.Equals("ASC") ? "▲" : "▼";
                    // 将label添加到列控件里
                    e.Row.Cells[this.gridView.Columns.IndexOf(dataControlField)].Controls.Add(label);
                }
            }
        }
    }
    #endregion

    #region protected void gridView_RowEditing(object sender, GridViewEditEventArgs e) 编辑列表时
    /// <summary>
    /// 编辑列表事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        // 获取删除和组件
        string id = this.gridView.DataKeys[e.NewEditIndex].Values["Id"].ToString();
        // 判断是否带加载效果
        if (Utilities.IsLoading)
            // 转向设置密码页面（带加载效果）
            // 转向用户编辑页面
            Page.Response.Redirect(Utilities.LoadingPageUrl + Server.UrlEncode("Modules/Basic/Common/UserAdmin/UserEdit.aspx?ID=" + id + "&ReturnPage=../../../../Modules/Basic/Common/UserAdmin/UserAdmin.aspx"));
        else
            // 转向用户编辑页面
            Page.Response.Redirect("UserEdit.aspx?ID=" + id + "&ReturnPage=UserAdmin.aspx'");
    }
    #endregion

    #region protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e) 删除事件
    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        // 获取删除主键
        string id = this.gridView.DataKeys[e.RowIndex].Value.ToString();
        // 删除事件
        this.DeleteMark(id);
    }
    #endregion

    #region protected void btnRegistration_Click(object sender, EventArgs e) 注册事件
    /// <summary>
    /// 注册事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRegistration_Click(object sender, EventArgs e)
    {
        // 判断是否带加载效果
        if (Utilities.IsLoading)
            // 转向注册页面带加载效果
            Page.Response.Redirect(Utilities.LoadingPageUrl + Server.UrlEncode("Modules/Basic/Common/UserAdmin/Registration.aspx?Role=" + this.cmbRole.SelectedValue + "&ReturnPage=../../../../Modules/Basic/Common/UserAdmin/UserAdmin.aspx"));
        else
            // 转向注册页面
            Page.Response.Redirect("Registration.aspx?Role=" + this.cmbRole.SelectedValue + "&ReturnPage=../../../../Modules/Basic/Common/UserAdmin/UserAdmin.aspx");
    }
    #endregion

    #region protected void btnSetPassword_Click(object sender, EventArgs e) 密码
    /// <summary>
    /// 密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSetPassword_Click(object sender, EventArgs e)
    {
        // 批量设置密码
        string[] ids = Utilities.GetSelecteIds(this.gridView);
        // 批量字符串
        string idList = BaseBusinessLogic.ArrayToList(ids);
        // 判断是否带加载效果
        if (Utilities.IsLoading)
            // 转向设置密码页面（带加载效果）
            Page.Response.Redirect(Utilities.LoadingPageUrl + Server.UrlEncode("Modules/Basic/Common/UserAdmin/SetPassword.aspx?ID=" + idList + "&ReturnPage=../../../../Modules/Basic/Common/UserAdmin/UserAdmin.aspx"));
        else
            // 转向设置密码页面
            Page.Response.Redirect("SetPassword.aspx?ID=" + idList + "&ReturnPage=../../../../Modules/Basic/Common/UserAdmin/UserAdmin.aspx");
    }
    #endregion

    #region protected void btnDelete_Click(object sender, EventArgs e) 批量删除事件
    /// <summary>
    /// 批量删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        // 批量删除
        this.BathDelete();
    }
    #endregion

    #region protected void gridView_Sorting(object sender, GridViewSortEventArgs e) 排序事件
    /// <summary>
    /// 排序事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (this.SortDire == "ASC")
        {
            this.SortDire = "DESC";
        }
        else
        {
            this.SortDire = "ASC";
        }
        this.SortExpression = e.SortExpression;
        this.DTUser.DefaultView.Sort = this.SortExpression + " " + this.SortDire;
        this.gridView.EditIndex = -1;
        this.BindAspNetPagerData(this.gridView, aspNetPager, this.DTUser);
        this.SetButtomState();
    }
    #endregion

    #region protected void btnPass_Click(object sender, EventArgs e) 解锁事件
    /// <summary>
    /// 解锁事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPass_Click(object sender, EventArgs e)
    {
        // 批量设置已处理
        this.BathPass();
    }
    #endregion

    #region protected void btnLock_Click(object sender, EventArgs e) 加锁事件
    /// <summary>
    /// 加锁事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnLock_Click(object sender, EventArgs e)
    {
        // 批量设置未处理
        this.BathLock();
    }
    #endregion

    #region protected void aspNetPager_PageChanged(object sender, EventArgs e) 执行分页动作
    /// <summary>
    /// 执行分页动作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void aspNetPager_PageChanged(object sender, EventArgs e)
    {
        this.DoSearch();
    }
    #endregion
}